<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
require_once (APPPATH . 'controllers/LISTENER.php');

class fbtest extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    public function index() {
        $array_keys = array_keys($_POST);                 //strips all html and script tags globally//
        for ($i = 0; $i < count($array_keys); $i++) {
            $_POST[$array_keys[$i]] = strip_tags($_POST[$array_keys[$i]], '<meta>,<link>');
        }

        $source_url = isset($_POST['url']) ? $_POST['url'] : null;

        if (empty($source_url)) {
            echo '<font face="arial" color="#999999">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &uarr; Enter your URL above &uarr;</font>';
        } else {
            $url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=" . urlencode($source_url);
            $xml = file_get_contents($url);
            $xml = simplexml_load_string($xml);

            echo "For the site:<b> $source_url:</b><br />";

            echo "Share &rarr; " . $shares = $xml->link_stat->share_count;
            echo "<br/>";

            echo "Like &rarr; " . $likes = $xml->link_stat->like_count;
            echo "<br/>";

            echo "Comments &rarr; " . $comments = $xml->link_stat->comment_count;
            echo "<br/>";

            echo "Total &rarr; " . $total = $xml->link_stat->total_count;
            echo "<br/>";
            die;
        }
        $this->load->view('header');
        $this->load->view('fbtest');
        $this->load->view('footer');
    }

}

?>
